package com.kangtu.demointerceptor02.config;

import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: demo-weix-pay
 * @description: ApiInterceptor
 * @author: 亮子说编程
 * @create: 2021-03-05 18:32
 **/

public class ApiInterceptor extends HandlerInterceptorAdapter {
    /**
     * 在请求处理之前进行调用（Controller方法调用之前）
     * 基于URL实现的拦截器
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String path = request.getServletPath();
        if (path.matches("/login")) {
            //不需要的拦截直接过
            System.out.println("=========== 放过 =========================");
            return true;
        } else {
            // 这写你拦截需要干的事儿，比如取缓存，SESSION，权限判断等
            System.out.println("====================================");
            return true;
        }
    }
}